package com.oweight.sagacious.payment.interfaces.controller;

import com.oweight.sagacious.api.model.msg.Message;
import com.oweight.sagacious.auth.client.annotation.IgnoreClientToken;
import com.oweight.sagacious.auth.client.annotation.IgnoreUserToken;
import com.oweight.sagacious.common.context.BaseContextHandler;
import com.oweight.sagacious.payment.domain.model.AliPayRefundModel;
import com.oweight.sagacious.payment.domain.model.AliPayUnifiedOrder;
import com.oweight.sagacious.payment.domain.service.IAliPayManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 支付宝统一下单：Controller
 *
 * @author SAGE
 * @version v1 2019-11-15 11:48:09
 */
@IgnoreUserToken
@IgnoreClientToken

@RestController
@RequestMapping("/api/ali")
public class AliPayController {

    @Autowired
    private IAliPayManager aliPayManager;

    /**
     * APP下单
     *
     * @param order
     * @return com.oweight.sagacious.api.model.msg.Message
     * @author zhougm
     * @version 2019/11/15 13:41
     */
    @PostMapping("/app/order/{configId}")
    public Message appOrder(@RequestBody AliPayUnifiedOrder order, @PathVariable String configId) {
        BaseContextHandler.set("ali_pay_config_id", configId);

        return aliPayManager.appOrder(order);
    }

    /**
     * 统一收单交易支付
     *
     * @param order
     * @return
     */
    @PostMapping("/order/{configId}")
    public Message order(@RequestBody AliPayUnifiedOrder order, @PathVariable String configId) {
        BaseContextHandler.set("ali_pay_config_id", configId);

        return aliPayManager.order(order);
    }

    /**
     * 统一退款
     *
     * @param refundModel
     * @return
     */
    @PostMapping("/refund/{configId}")
    public Message refund(@RequestBody AliPayRefundModel refundModel, @PathVariable String configId) {
        BaseContextHandler.set("ali_pay_config_id", configId);

        return aliPayManager.refund(refundModel);
    }
}
